import HtmlWebpackPlugin from 'html-webpack-plugin'
import paths from './paths'
import { Configuration } from 'webpack'

const baseConfig: Configuration = {
  output: {
    clean: true,
    path: paths.build,
    filename: 'assets/js/[name].[contenthash].js',
    publicPath: '/',
  },
  module: {
    rules: [
      {
        use: 'babel-loader',
        test: /\.(ts|tsx)$/,
        exclude: /node_modules/,
      },
      {
        use: ['style-loader', 'css-loader', 'postcss-loader'],
        test: /\.css$/,
      },
      {
        type: 'asset',
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.json', '.jsx'],
    alias: {
      '@': paths.src,
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      inject: true,
      template: 'public/index.html',
      favicon: 'public/favicon.ico',
    }),
  ],
}

export default baseConfig
